feat(sso) expired token session redirect#2051
Conversation
0226b0d to
54c6e05
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the UI’s behavior when running behind oauth2-proxy by distinguishing “unsecured” (no proxy/header) from “expired” (proxy session valid but forwarded id_token expired) and triggering a guarded re-auth redirect for the expired case, instead of silently rendering a logged-out UI.
Changes:
- Change
getCurrentUser()to return an{ status, user }result (authenticated | expired | unsecured) instead ofCurrentUser | null. - Add
statustoAuthContextand implement a sessionStorage-based loop guard + redirect to/oauth2/start?rd=...when status isexpired. - Add unit tests for the new auth status model and AuthContext redirect/guard behavior; update auth architecture docs and add an EP describing the design.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/src/contexts/AuthContext.tsx | Adds AuthStatus to context and performs guarded oauth2-proxy re-auth redirect on expired. |
| ui/src/contexts/tests/AuthContext.test.tsx | Tests redirect/guard behavior and the new status value exposed by the provider. |
| ui/src/app/login/page.tsx | Minor layout tweak on the login page container. |
| ui/src/app/actions/auth.ts | Introduces AuthStatus/AuthResult and returns structured auth state from getCurrentUser(). |
| ui/src/app/actions/tests/auth.test.ts | Tests getCurrentUser()’s new { status, user } contract. |
| docs/OIDC_PROXY_AUTH_ARCHITECTURE.md | Documents the three auth states and the re-auth flow in the auth boundary diagram/rationale. |
| design/EP-2045-sso-session-expiry-redirect.md | Adds a design EP explaining the motivation, approach, and test plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
3 small questions nr1// auth.ts : when nr2// jwt.ts: nr3// AuthContext.tsx : |
Address review feedback on PR kagent-dev#2051: - jwt: treat a missing `exp` claim as expired instead of valid-forever, so a non-compliant/garbled id_token forces re-auth rather than being trusted. - AuthContext: widen REAUTH_GUARD_WINDOW_MS 10s -> 60s so a slow IdP round-trip isn't misread as a failed redirect loop. - Add jwt unit tests covering decode (valid/malformed) and isTokenExpired (future/past/missing exp). Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
|
Thanks @mesutoezdil — all three are fair points. Addressed in the latest commit: nr2 (jwt.ts — missing nr3 (AuthContext.tsx — guard window): Bumped nr1 (auth.ts — malformed token → Also added |
Address review feedback on PR kagent-dev#2051: - jwt: treat a missing `exp` claim as expired instead of valid-forever, so a non-compliant/garbled id_token forces re-auth rather than being trusted. - AuthContext: widen REAUTH_GUARD_WINDOW_MS 10s -> 60s so a slow IdP round-trip isn't misread as a failed redirect loop. - Add jwt unit tests covering decode (valid/malformed) and isTokenExpired (future/past/missing exp). Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
b259fca to
aed3178
Compare
Distinguish authenticated/expired/unsecured auth states in the UI. When behind oauth2-proxy and the forwarded id_token has expired (but the proxy session is still valid), re-run the OIDC flow via /oauth2/start instead of silently rendering a logged-out UI. Never redirect in unsecured mode, and guard against redirect loops via a sessionStorage window. Review hardening: - jwt: treat a missing `exp` claim as expired rather than valid-forever, so a non-compliant id_token forces re-auth instead of being trusted. - AuthContext: widen the re-auth loop guard 10s -> 60s so a slow IdP round-trip isn't misread as a failed redirect loop. Includes jest coverage (getCurrentUser auth states, AuthProvider redirect/guard, jwt decode + isTokenExpired), design/EP-2045-sso-session-expiry-redirect.md, and NEXT_PUBLIC_SSO_REDIRECT_PATH wiring in the Helm chart. Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
aed3178 to
8eabd19
Compare
Improve SSO expired token redirect (#2045)
This pull request implements robust handling of SSO session expiry in the UI when deployed behind an OIDC proxy (such as oauth2-proxy). The main improvements are the introduction of a clear authentication status model, transparent re-authentication when the session expires, and safeguards against redirect loops. The changes ensure users are not unexpectedly logged out when their forwarded token expires, while avoiding infinite redirects in unsecured (no proxy) environments. Comprehensive unit tests and documentation updates are included.
Authentication state handling and re-authentication flow:
AuthStatusmodel ("authenticated","expired","unsecured") and updatedgetCurrentUserto return a structuredAuthResultreflecting these states. This allows the UI to distinguish between a missing proxy, an expired token, and a valid session. [1] [2]AuthProviderinAuthContext.tsxto trigger a redirect to the OIDC re-auth endpoint (/oauth2/start) only when the session is"expired", never in"unsecured"mode. Added asessionStorage-based guard to prevent redirect loops if re-authentication fails to refresh the token. The guard is cleared on successful authentication. [1] [2] [3]Testing and reliability:
getCurrentUserto cover all authentication states, ensuring correct status assignment and token handling.AuthProviderto verify redirect and guard logic, including prevention of redirect loops and correct guard clearing on authentication.Documentation and UI updates:
OIDC_PROXY_AUTH_ARCHITECTURE.mdwere updated for clarity. [1] [2]These changes collectively ensure a seamless and predictable authentication experience for users behind SSO, while maintaining safe behavior in unsecured deployments.